import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.RPC;
import protocol.MyProtocol;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Scanner;

/**
 * @author rikun
 */
public class Client {
    public static void main(String[] args) {
        try {
            MyProtocol proxy =
                    RPC.getProxy(MyProtocol.class,
                                1L,
                                new InetSocketAddress("127.0.0.1",8848),
                                new Configuration());

            System.out.println("请输入：");
            Scanner reader=new Scanner(System.in);
            String str = reader.nextLine();
            while (!"exit".equals(str)) {
                if (StringUtils.isAllBlank(str)) {
                    str = reader.nextLine();
                    // 输入 exit 退出
                    if ("exit".equals(str)) {
                        break;
                    }
                }else {
                    System.out.println(proxy.getNameById(str));
                    str = "";
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
